import math
from pydub import AudioSegment

# 切割音频文件

audio = AudioSegment.from_file('./output1.wav',format='wav',frame_rate=16000, channels=1)

# print(audio.frame_rate)
#ms => sec
# sec = (audio.__len__()/1000)
#sec => minute
# minute = int(sec/60)
# surplus_sec = int(sec%60)

loop_num = math.ceil(audio.__len__() / 3000)
print(loop_num)

for i in range(0, loop_num):
    start = i*1000
    end = start+1000
    sound = audio[start:end]
    print(sound.__len__())
    file_name = './test/'+str(i) + ".wav"
    sound.export(file_name, format='wav')

